//
//  AlittleCell.swift
//  newshaohuo
//
//  Created by shaohuo on 2018/2/6.
//  Copyright © 2018年 shaohuo. All rights reserved.
//

import Foundation

class AlittleCell: UITableViewCell {
    
    @IBOutlet weak var orderNumberLabel: UILabel!
    @IBOutlet weak var timeLabel: UILabel!
    @IBOutlet weak var IdentificationLabel: UILabel!
        @IBOutlet weak var itemNameLabel: UILabel!
    @IBOutlet weak var middleView: UIView!
    @IBOutlet weak var senderLabel: UILabel!
    @IBOutlet weak var recoderButton: UIButton!
    @IBOutlet weak var recoderButtonWidth: NSLayoutConstraint!
    @IBOutlet weak var recipientLabel: UILabel!
    @IBOutlet weak var orderStateLabel: UILabel!
    @IBOutlet weak var amountPayLabel: UILabel!

    var satusdict = ["1":"待付款","2":"待应答","3":"待取件","4":"待收件","5":"待确认","6":"已完成","7":"已取消"]
    
    var recoder_manager = RecordManager()//初始化
    
    var _alittleOrderItem: AlittleOrderItem!
    
    var alittleOrderItem : AlittleOrderItem! {
        get {
            return _alittleOrderItem
        }
        set {
            _alittleOrderItem = newValue
            orderNumberLabel.text = _alittleOrderItem.order_num
            timeLabel.text = _alittleOrderItem.operate_time
            IdentificationLabel.text = textHoldUp(oldStr: _alittleOrderItem.func_name)
            
            if _alittleOrderItem?.video_time=="-1"{//文字
                recoderButton.isHidden = true
                itemNameLabel.isHidden = false
                itemNameLabel.text = _alittleOrderItem.item_name
            }else {//语音
                itemNameLabel.isHidden = true
                recoderButton.isHidden = false
                recoderButton.setTitle("\(_alittleOrderItem.video_time)''", for: .normal)
                recoderButtonWidth.constant = CGFloat(Int(_alittleOrderItem.video_time)!*10+40)
            }

            orderStateLabel.text = satusdict[_alittleOrderItem.status]
            amountPayLabel.text = "应付金额:¥"+(_alittleOrderItem?.shipping_fee)!+"元"
            
        }
    }
    //播放语音
    @IBAction func recoderBtnAction(_ sender: UIButton) {
        recoder_manager.playRecoder(filePath: "\(endpoint)\(_alittleOrderItem.item_name)")
    }
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
    
    }
    
    func textHoldUp(oldStr:String) -> String {
        var newStr : String = ""
        for charStr in oldStr {
            newStr.append(charStr)
            newStr.append("\n")
        }
        return newStr
    }
    
}
